/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchPersonPanel.java
 *
 * Created on Jul 13, 2011, 10:50:55 AM
 */
package panels;

import dao.RoleDao;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import obj.Person;
import conn.EMIS4Connection;
import java.sql.Connection;
import java.sql.Date;
import java.util.Iterator;
import java.util.List;
import javax.swing.ComboBoxModel;
import obj.Role;

/**
 *
 * @author cjlopez
 */
public class SearchPersonPanel extends javax.swing.JPanel {

    //** Get Connection */
    EMIS4Connection database = EMIS4Connection.getInstance();
    Connection conn = database.getConnection();
    RoleDao roleDao = new RoleDao();
    List<Role> roles = null;

    /** Creates new form SearchPersonPanel */
    public SearchPersonPanel() {
        initComponents();
    }

    public String[] RoleBox() {
        //** Create Role ComboBox Content
        try {
            roles = roleDao.loadAll(conn);
        } catch (SQLException ex) {
            Logger.getLogger(SearchPersonPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        Iterator<Role> roleIt = roles.iterator();
        String[] roleArray = new String[roles.size()];
        int i = 0;
        while (roleIt.hasNext()) {
            roleArray[i] = roleIt.next().getName();
            i++;
        }
        roleArray.toString();
        return roleArray;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    firstNameField = new javax.swing.JTextField();
    lastNameField = new javax.swing.JTextField();
    dobField = new javax.swing.JTextField();
    ssnField = new javax.swing.JTextField();
    emailField = new javax.swing.JTextField();
    phone1Field = new javax.swing.JTextField();
    phone2Field = new javax.swing.JTextField();
    personIDField = new javax.swing.JTextField();
    jButton1 = new javax.swing.JButton();
    jPanel1 = new javax.swing.JPanel();
    jComboBox1 = new javax.swing.JComboBox();
    jComboBox2 = new javax.swing.JComboBox(RoleBox());

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
    jLabel1.setText("Member Search Page");
    jLabel1.setName("jLabel1"); // NOI18N

    jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel2.setText("First Name:");
    jLabel2.setName("jLabel2"); // NOI18N

    jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel3.setText("Last Name:");
    jLabel3.setName("jLabel3"); // NOI18N

    jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel4.setText("Date of Birth:"); // NOI18N
    jLabel4.setName("jLabel4"); // NOI18N

    jLabel5.setText("SSN:");
    jLabel5.setName("jLabel5"); // NOI18N

    jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel6.setText("Email:");
    jLabel6.setName("jLabel6"); // NOI18N

    jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel7.setText("Phone1");
    jLabel7.setName("jLabel7"); // NOI18N

    jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel8.setText("Phone2:");
    jLabel8.setName("jLabel8"); // NOI18N

    jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel9.setText("Gender:");
    jLabel9.setName("jLabel9"); // NOI18N

    jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel10.setText("Person ID:");
    jLabel10.setName("jLabel10"); // NOI18N

    jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
    jLabel11.setText("Role:");
    jLabel11.setName("jLabel11"); // NOI18N

    firstNameField.setFont(new java.awt.Font("Tahoma", 0, 12));
    firstNameField.setText("jTextField1");
    firstNameField.setName("firstNameField"); // NOI18N

    lastNameField.setFont(new java.awt.Font("Tahoma", 0, 12));
    lastNameField.setText("jTextField2");
    lastNameField.setName("lastNameField"); // NOI18N

    dobField.setFont(new java.awt.Font("Tahoma", 0, 12));
    dobField.setText("jTextField3");
    dobField.setName("dobField"); // NOI18N

    ssnField.setColumns(9);
    ssnField.setFont(new java.awt.Font("Tahoma", 0, 12));
    ssnField.setText("jTextField4");
    ssnField.setName("ssnField"); // NOI18N

    emailField.setFont(new java.awt.Font("Tahoma", 0, 12));
    emailField.setText("jTextField5");
    emailField.setName("emailField"); // NOI18N

    phone1Field.setFont(new java.awt.Font("Tahoma", 0, 12));
    phone1Field.setText("jTextField6");
    phone1Field.setName("phone1Field"); // NOI18N

    phone2Field.setFont(new java.awt.Font("Tahoma", 0, 12));
    phone2Field.setText("jTextField7");
    phone2Field.setName("phone2Field"); // NOI18N

    personIDField.setColumns(10);
    personIDField.setFont(new java.awt.Font("Tahoma", 0, 12));
    personIDField.setText("jTextField9");
    personIDField.setName("personIDField"); // NOI18N

    jButton1.setText("Search");
    jButton1.setName("jButton1"); // NOI18N
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jPanel1.setName("jPanel1"); // NOI18N

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 249, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 345, Short.MAX_VALUE)
    );

    jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 12));
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "M", "F", "?" }));
    jComboBox1.setName("jComboBox1"); // NOI18N

    jComboBox2.setName("jComboBox2"); // NOI18N

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel1)
              .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                  .addComponent(jLabel2)
                  .addComponent(jLabel3)
                  .addComponent(jLabel4)
                  .addComponent(jLabel5)
                  .addComponent(jLabel6)
                  .addComponent(jLabel7)
                  .addComponent(jLabel8)
                  .addComponent(jLabel9)
                  .addComponent(jLabel10)
                  .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(firstNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                  .addComponent(lastNameField)
                  .addComponent(dobField)
                  .addComponent(ssnField)
                  .addComponent(emailField)
                  .addComponent(phone1Field)
                  .addComponent(phone2Field)
                  .addComponent(personIDField))))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addComponent(jButton1)
            .addContainerGap())))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel2)
              .addComponent(firstNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel3)
              .addComponent(lastNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel4)
              .addComponent(dobField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel5)
              .addComponent(ssnField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel6)
              .addComponent(emailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel7)
              .addComponent(phone1Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel8)
              .addComponent(phone2Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel9)
              .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel10)
              .addComponent(personIDField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel11)
              .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
        .addComponent(jButton1)
        .addContainerGap())
    );
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Person person = new Person();
        if(! personIDField.getText().isEmpty()) {
            person.setPersonID(Integer.parseInt(personIDField.getText()));
        }
        if (! firstNameField.getText().isEmpty()) {
            person.setFirstName(firstNameField.getText());
        }
        if (! lastNameField.getText().isEmpty()) {
            person.setLastName(lastNameField.getText());
        }
        if (! dobField.getText().isEmpty()) {
            //person.setDateOfBirth(Date.valueOf(dobField.getText()));
        }
        if (! ssnField.getText().isEmpty()) {
            person.setSSN(Integer.parseInt(ssnField.getText()));
        }
        if (! emailField.getText().isEmpty()) {
            person.setEmail(emailField.getText());
        }
        if (! phone1Field.getText().isEmpty()) {
            //person.setPhoneNumberPrimary(phone1Field.getText());
        }
        if (! phone2Field.getText().isEmpty()) {
            //person.setPhoneNumberSecondary(phone2Field.getText());
        }
        if (! jComboBox1.getSelectedItem().toString().isEmpty()) {
            //person.setGender(jComboBox1.getSelectedItem().toString());
        }
        if(! jComboBox2.getSelectedItem().toString().isEmpty()) {
            //person.setRoleID(jComboBox2.getSelectedIndex());
        }
        System.out.println("Searching: ");
        person.toString();
    }//GEN-LAST:event_jButton1ActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JTextField dobField;
  private javax.swing.JTextField emailField;
  private javax.swing.JTextField firstNameField;
  private javax.swing.JButton jButton1;
  private javax.swing.JComboBox jComboBox1;
  private javax.swing.JComboBox jComboBox2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JTextField lastNameField;
  private javax.swing.JTextField personIDField;
  private javax.swing.JTextField phone1Field;
  private javax.swing.JTextField phone2Field;
  private javax.swing.JTextField ssnField;
  // End of variables declaration//GEN-END:variables
}
